home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- #
- # TV-Man.Video.c
- #
- # Copyright © Apple Computer, Inc. 1989-1990
- # All rights reserved.
- #
- #
- #
- # All the pertinent code which provides the video patterns are found in this file.
- #
- # In order to have an evironment which predictable events happen several definitions
- # must be established. The most critical is in the file architecture. Each functional
- # block will have its own source and header file. The main project file, in this
- # case TV-Man, will have its header file included with all other files. This will
- # allow for global constants. The utility source file shall contain functions that
- # are general purpose in nature and that can be used by all other functions. These
- # are intended not to be application or major block specific. In order for this to be
- # accomodated all functions in the utility source file must use only the information
- # that is passed to them or information that can be gleaned from the system via
- # toolbox calls. There will be no header file associated with the utility file as this
- # will destroy the intent of the utilities.
- #
- # There are several files which contain information which is global in nature .These
- # file are included in the main project header file. They are: x.Errors.h, x.Ext.h,
- # x.Protos.h, x.Menus.h. The reason for containing them in seperate files is one of
- # convienience and accesability.
- #
- #
- # Revision Log:
- #
- # 11-05-91 RGK Added the menu items for single color screens
- # 04-26-91 RGK Creation
- #
- #
- ------------------------------------------------------------------------------*/
-
-
- /*------------------------------------------------------------------------------*/
- /* This is a list of all local includes necessary for this pregram. */
-
- #include "TV-Man.h"
- #include "TV-Man.Video.h"
-
-
-
- /*------------------------------------------------------------------------------*/
- /* This draws the Test Pattern which is the display shown at the beginning */
-
- void DrawTestPattern(window)
- WindowPtr window;
- {
- Rect box;
- short vcenter, hcenter, offset, space, width, ringcount;
- TPValuesHdl TPVHdl;
-
- TPVHdl = (TPValuesHdl)GetResource('tpat',rTestPattern);
- if((TPVHdl == nil) || (ResError() != noErr))
- {
- Error(eMinor, eMinorRsrc);
- gVideoPattern = gLastVideoPattern; /* reset to previous pattern */
- InvalRect(&window->portRect); /* invalidate entire window */
- }
- else
- {
- PenSize((*TPVHdl)->LineWidth, (*TPVHdl)->LineWidth);
- ForeColor((*TPVHdl)->ForeGColor);
- BackColor((*TPVHdl)->BackGColor);
- EraseRect(&(window->portRect)); /* this forces a full window to set the background */
-
- /* the next two lines are just for read ability later */
-
- width = (*TPVHdl)->LineWidth;
- space = (*TPVHdl)->SpaceWidth;
-
-
- WhereCenter(window, &hcenter, &vcenter);
-
-
- /* draw a vertical line remember to subtract out 1/2 the line width to adjust for
- calculation from the center of the line */
-
- MoveTo(hcenter - (width/2), window->portRect.top);
- LineTo(hcenter - (width/2), window->portRect.bottom);
-
-
- /* draw a horizontal line */
-
- MoveTo(window->portRect.left, vcenter - (width/2));
- LineTo(window->portRect.right, vcenter - (width/2));
-
-
- /* now the upper left to lower right diagonal*/
-
- MoveTo(window->portRect.left - (width/2), window->portRect.top - (width/2));
- LineTo(window->portRect.right - (width/2), window->portRect.bottom - (width/2));
-
-
- /* now the other diagonal */
-
- MoveTo(window->portRect.left - (width/2), window->portRect.bottom - (width/2));
- LineTo(window->portRect.right - (width/2), window->portRect.top - (width/2));
-
-
- /* This next bit draws concentric circles about the center of the window. The variable
- 'space' determines the number of pixels between each ring. The variable 'stop' determines
- the number of circles by calculating the vertical width of the window and seeing how many
- rings of the width 'space' there can be. The loop then draws the rings. */
-
- PenSize((*TPVHdl)->RingWidth, (*TPVHdl)->RingWidth);
- width = (*TPVHdl)->RingWidth;
- ringcount = 0;
- offset = space + width;
-
- while (ringcount < ((window->portRect.bottom - window->portRect.top)/2)
- /(space + width))
- {
- SetRect(&box, hcenter - offset,
- vcenter - offset, hcenter + offset,
- vcenter + offset);
- FrameOval(&box);
- offset = offset + space + width;
- ringcount = ringcount + 1;
- }
- }
- ReleaseResource((Handle)TPVHdl);
- }/* DrawTestPattern */
-
-
-
-
- /*------------------------------------------------------------------------------*/
- /* Do the Standard Color Bars */
-
- void DrawColorBars(window)
- WindowPtr window;
- {
- short offset = 0;
- short count = 0;
- short width;
- Rect bar;
- PaletteHandle PaletteHdl;
-
-
- PaletteHdl = GrabPalette(window, ColorDepth, COLOR);
- width = SizeVBar(window, CBarCount); /* Only 16 bars for this display */
-
- /* This loop gets the color pointed to and paints the calculated bar with it */
-
- while (offset < window->portRect.right)
- {
- SetRect( &bar, window->portRect.left + offset, window->portRect.top,
- window->portRect.left + width + offset, window->portRect.bottom);
- offset = window->portRect.left + width + offset;
- PmForeColor(count);
- PaintRect(&bar);
- count = count + 1;
- }
- DisposePalette(PaletteHdl);
- }/* DrawColorBars */
-
-
-
-
-
-
- /*------------------------------------------------------------------------------*/
- /* The next four functions are just set up the color parameter for
- the call to tdraw the screen one color */
-
- void DrawRedScreen(window)
- WindowPtr window;
- {
- DrawSingleColor(window, RedScreenCol);
- }
- /* DrawRedScreen */
-
-
- void DrawGreenScreen(window)
- WindowPtr window;
- {
- DrawSingleColor(window, GreenScreenCol);
- }
- /* DrawGreenScreen */
-
-
- void DrawBlueScreen(window)
- WindowPtr window;
- {
- DrawSingleColor(window, BlueScreenCol);
- }
- /* DrawBlueScreen */
-
-
- void DrawWhiteScreen(window)
- WindowPtr window;
- {
- DrawSingleColor(window, WhiteScreenCol);
- }
- /* DrawwhiteScreen */
-
-
-
-
-
-
- /*------------------------------------------------------------------------------*/
- /* Color the screen one color */
-
- void DrawSingleColor(window, index)
- WindowPtr window;
- short index;
- {
- short offset = 0;
- short width;
- Rect bar;
- PaletteHandle PaletteHdl;
-
-
- PaletteHdl = GrabPalette(window, ColorDepth, COLOR);
- width = SizeVBar(window, 1); /* Only 1 bar for this display */
-
- /* This loop gets the color pointed to and paints the calculated bar with it */
-
- while (offset < window->portRect.right)
- {
- SetRect( &bar, window->portRect.left + offset, window->portRect.top,
- window->portRect.left + width + offset, window->portRect.bottom);
- offset = window->portRect.left + width + offset;
- PmForeColor(index);
- PaintRect(&bar);
- }
- DisposePalette(PaletteHdl);
- }/* DrawSingleColor */
-
-
-
- /*------------------------------------------------------------------------------*/
- /* Do the Gray scale from light to dark */
-
- void DrawGrayScaleLD(window)
- WindowPtr window;
- {
- short offset = 0;
- short colorindx = 1;
- short width, depth, barcount, *resourcePtr, **resourceHdl;
- Rect bar;
- PaletteHandle PaletteHdl;
-
-
- resourceHdl = (short**)GetResource('gbrs',rGrayValues);
- if((resourceHdl == nil) || (ResError() != noErr))
- {
- Error(eMinor, eMinorRsrc);
- gVideoPattern = gLastVideoPattern; /* reset to previous pattern */
- InvalRect(&window->portRect); /* invalidate entire window */
- }
- else
- {
- depth = **resourceHdl;
- resourcePtr = *resourceHdl;
- barcount = *(resourcePtr + 1);
- ReleaseResource((Handle)resourceHdl);
-
- PaletteHdl = GrabPalette(window, depth, GRAY);
- width = SizeVBar(window, barcount);
- colorindx = 1;
-
- /* This loop paints the calculated bar with it */
-
- while (offset < window->portRect.right)
- {
- SetRect( &bar, window->portRect.left + offset, window->portRect.top,
- window->portRect.left + width + offset, window->portRect.bottom);
- offset = window->portRect.left + width + offset;
- PmForeColor(colorindx - 1);
- PaintRect(&bar);
- if(depth/barcount < 1) colorindx = colorindx + 1;
- else colorindx = colorindx + (depth/(barcount - 1));
- if(colorindx > depth) colorindx = 1;
- }
- }
- DisposePalette(PaletteHdl);
- }/* DrawGrayScaleLD */
-
-
-
-
- /*------------------------------------------------------------------------------*/
- /* Do the Gray scale from dark to light */
-
- void DrawGrayScaleDL(window)
- WindowPtr window;
- {
- short offset = 0;
- short colorindx = 1;
- short width, depth, barcount, *resourcePtr, **resourceHdl;
- Rect bar;
- PaletteHandle PaletteHdl;
-
-
- resourceHdl = (short**)GetResource('gbrs',rGrayValues);
- if((resourceHdl == nil) || (ResError() != noErr))
- {
- Error(eMinor, eMinorRsrc);
- gVideoPattern = gLastVideoPattern; /* reset to previous pattern */
- InvalRect(&window->portRect); /* invalidate entire window */
- }
- else
- {
- depth = **resourceHdl;
- resourcePtr = *resourceHdl;
- barcount = *(resourcePtr + 1);
- ReleaseResource((Handle)resourceHdl);
-
- PaletteHdl = GrabPalette(window, depth, GRAY);
- width = SizeVBar(window, barcount);
- colorindx = depth;
-
- /* This loop paints the calculated bar with it */
-
- while (offset < window->portRect.right)
- {
- SetRect( &bar, window->portRect.left + offset, window->portRect.top,
- window->portRect.left + width + offset, window->portRect.bottom);
- offset = window->portRect.left + width + offset;
- PmForeColor(colorindx - 1);
- PaintRect(&bar);
- if(depth/barcount < 1) colorindx = colorindx - 1;
- else colorindx = colorindx - (depth/(barcount - 1));
- if(colorindx < 1) colorindx = depth;
- }
- }
- DisposePalette(PaletteHdl);
- }/* DrawGrayScaleDL */
-
-
-
-
-
-
-
-
- /*------------------------------------------------------------------------------*/
- /* This draws vertical lines across the screen */
-
- void DrawVertLines(window)
- WindowPtr window;
- {
- short location, space, line;
- LNValuesHdl LNVHdl;
-
-
- LNVHdl = (LNValuesHdl)GetResource('lnes',rVLines);
- if((LNVHdl == nil) || (ResError() != noErr))
- {
- Error(eMinor, eMinorRsrc);
- }
- else
- {
- ForeColor((*LNVHdl)->LForeGColor);
- BackColor((*LNVHdl)->LBackGColor);
- EraseRect(&(window->portRect)); /* this forces a full window redraw to set the background */
-
- space = (*LNVHdl)->LBackGCWidth; /* just for read ability later */
- line = (*LNVHdl)->LForeGCWidth; /* just for read ability later as well */
- PenSize((*LNVHdl)->LForeGCWidth, (*LNVHdl)->LForeGCWidth);
-
- /* This next bit draws vertical lines through the window. The variable
- 'space' determines the number of pixels between each line. The variable
- 'stop' determines the number of lines by calculating the width of the
- window and seeing how many lines of the combined width 'space'and the
- darkcolor width there can be. The for loop then draws the lines. */
-
- for(location = window->portRect.left + space;
- location < window->portRect.right;
- location = location + space + line)
- {
- MoveTo(window->portRect.left + location, window->portRect.top);
- LineTo(window->portRect.left + location, window->portRect.bottom);
- }
- }
- ReleaseResource((Handle)LNVHdl);
- }/* DrawVertLines */
-
-
-
-
-
-
-
- /*------------------------------------------------------------------------------*/
- /* This draws horizontal lines across the screen */
-
- void DrawHorzLines(window)
- WindowPtr window;
- {
- short location, space, line;
- LNValuesHdl LNVHdl;
-
-
- LNVHdl = (LNValuesHdl)GetResource('lnes',rVLines);
- if((LNVHdl == nil) || (ResError() != noErr))
- {
- Error(eMinor, eMinorRsrc);
- gVideoPattern = gLastVideoPattern; /* reset to previous pattern */
- InvalRect(&window->portRect); /* invalidate entire window */
- }
- else
- {
- ForeColor((*LNVHdl)->LForeGColor);
- BackColor((*LNVHdl)->LBackGColor);
- EraseRect(&(window->portRect)); /* this forces a full window redraw to set the background */
-
- space = (*LNVHdl)->LBackGCWidth; /* just for read ability later */
- line = (*LNVHdl)->LForeGCWidth; /* just for read ability later as well */
- PenSize((*LNVHdl)->LForeGCWidth, (*LNVHdl)->LForeGCWidth);
-
- /* This next bit draws horizontal lines through the window. The variable
- 'space' determines the number of pixels between each line. The variable
- 'stop' determines the number of lines by calculating the height of the
- window and seeing how many lines of the combined width 'space' and the
- darkcolor width there can be. The for loop then draws the lines. */
-
- for(location = window->portRect.top + space;
- location < window->portRect.bottom;
- location = location + space + line)
- {
- MoveTo(window->portRect.left, window->portRect.top + location);
- LineTo(window->portRect.right, window->portRect.top + location);
- }
- }
- ReleaseResource((Handle)LNVHdl);
- }/* DrawHorzLines */
-
-
-
-
- /*------------------------------------------------------------------------------*/
-
- void DrawLineBurst(window)
- WindowPtr window;
- {
- short location, space, line, count;
- LBurstHdl ResourceHdl;
-
-
- ResourceHdl = (LBurstHdl)GetResource('lbst',rLineBurst);
- if((ResourceHdl == nil) || (ResError() != noErr))
- {
- Error(eMinor, eMinorRsrc);
- gVideoPattern = gLastVideoPattern; /* reset to previous pattern */
- InvalRect(&window->portRect); /* invalidate entire window */
- }
- else
- {
- ForeColor((*ResourceHdl)->BarColor);
- BackColor((*ResourceHdl)->BackGColor);
- EraseRect(&(window->portRect)); /* this forces a full window redraw to set the background */
-
- space = (*ResourceHdl)->BarSpace; /* just for read ability later */
- line = (*ResourceHdl)->BarWidth; /* just for read ability later as well */
- PenSize((*ResourceHdl)->BarWidth, (*ResourceHdl)->BarWidth);
- location = window->portRect.left + space;
-
- /* This next bit draws verticlal lines through the window. The variable
- 'space' determines the number of pixels between each line. */
-
- for(count = 0;
- count < (*ResourceHdl)->BarCount;
- count = count + 1)
- {
- MoveTo(window->portRect.left + location, window->portRect.top);
- LineTo(window->portRect.left + location, window->portRect.bottom);
- location = location + space + line;
- }
- }
- ReleaseResource((Handle)ResourceHdl);
- }/* DrawLineBurst */
-
-
-
-
-
- /*------------------------------------------------------------------------------*/
- /* Locate the center of the appointed window. The origonal sizing of the
- window should make sure of an even value of window width and height */
-
- void WhereCenter(window, hcenter, vcenter)
- WindowPtr window;
- short *hcenter, *vcenter;
- {
- *hcenter = (window->portRect.right - window->portRect.left)/2;
- *vcenter = (window->portRect.bottom - window->portRect.top)/2;
- }/* WhereCenter */
-
-
-
-
-
-
- /*------------------------------------------------------------------------------*/
- /* return the width value of the bars that divide the window
- by the passed 'number' of bars */
-
- short SizeVBar(window,number)
- WindowPtr window;
- short number;
- {
- short width;
-
- width = (window->portRect.right - window->portRect.left)/number;
- if( width < 1) return 1;
- else return width;
- }/* SizeVBar */
-
-
-
-
-
-
-
- /*------------------------------------------------------------------------------*/
- /* This function sets up and returns the handle a palette. The request is made by
- passing the pixel depth. This is the number of colors or shades of gray
- available. A boolean value is also necessary which determines whether color
- palettes or gray scale palettes are to be used. */
-
- PaletteHandle GrabPalette(window, depth, type)
- WindowPtr window;
- short depth;
- Boolean type;
-
- {
- PaletteHandle PaletteHdl;
-
- if(type == GRAY)
- {
- if(depth == 256) PaletteHdl = GetNewPalette(rGPal8);
- else PaletteHdl = GetNewPalette(rGPal4);
- }
- else PaletteHdl = GetNewPalette(rColorPal);
- NSetPalette(window, PaletteHdl, pmNoUpdates);
- FlushEvents(everyEvent,0);
- return PaletteHdl;
- };/* GrabPalette */
-
-
-
-
-